package com.hdit.guimei.service.impl;

import com.hdit.guimei.domain.Goods;
import com.hdit.guimei.domain.GoodsOrder;
import com.hdit.guimei.domain.Order_item;
import com.hdit.guimei.domain.Order_table;
import com.hdit.guimei.mapper.GoodsMapper;
import com.hdit.guimei.mapper.MycommentMapper;
import com.hdit.guimei.mapper.OrderItemMapper;
import com.hdit.guimei.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @基本功能: 订单明细业务实现类
 * @ClassName: OrderItemServiceImpl
 * @Description: TODO
 * @Author: 李嘉明
 * @Date: 2021/1/19 10:42
 * @Version 1.0
 */
@Service
public class OrderItemServiceImpl implements OrderItemService {
    @Autowired
    private OrderItemMapper orderItemMapper;
    private GoodsMapper goodsMapper;
    private MycommentMapper mycommentMapper;
    private MycommentServiceImpl mycommentService;
    @Override
    /**
     * @Method: findAllOrders
     * @函数(方法)功能: 查询所有的订单，可在前端进行分类
     * @Author: 李嘉明
     * @params: []
     * @Return: java.util.List<com.hdit.guimei.domain.Order_item>
     * @Exception:
     * @Date: 2021/1/19 11:41
     */
    public List<Order_item> findAllOrders() {
        return orderItemMapper.findAllOrderItems();
    }

    @Override
    /**
     * @Method: updateOrderItemState
     * @函数(方法)功能: 修改展示订单状态页面的状态
     * @Author: 李嘉明
     * @params: [map]
     * @Return: int
     * @Exception:
     * @Date: 2021/1/19 11:42
     */
    public int updateOrderItemState(Map map) {
        return orderItemMapper.updateOrderState(map);
    }

    /**
     * @Method: addOrderItem
     * @函数(方法)功能: 添加订单信息
     * @Author: 李嘉明
     * @params: [order_item]
     * @Return: int
     * @Exception:
     * @Date: 2021/1/19 14:20
     */
    @Override
    public int addOrderItem(Order_item order_item) {
        //lvyazhe 改的  修改商品销量
        int i=goodsMapper.updateSales(order_item.getCount(),order_item.getGood_id());
        return orderItemMapper.addOrderItem(order_item);
    }
    /***
    * @Method 用户查看自己的订单状态
    * @Author 冰镇小可乐
    * @params  [id, order_state]
    * @Return java.util.List<com.hdit.guimei.domain.GoodsOrder>
    * @Exception
    * @Date 2021/1/21 19:57
    */
    @Override
    public List<GoodsOrder> findGoodsOrderFront(int id, int order_state) {
        List<GoodsOrder> list =mycommentService.findOrderGood(id,order_state);
        return list;
    }
    /***
    * @Method 后台订单管理
    * @Author 冰镇小可乐
    * @params  [order_state]
    * @Return java.util.List<com.hdit.guimei.domain.GoodsOrder>
    * @Exception  
    * @Date 2021/1/22 8:55
    */
    @Override
    public List<GoodsOrder> findGoodsOrderBehind(int order_state) {
        List<Order_table> order_tableList=orderItemMapper.findGoodsOrderBehind(order_state);
        List<GoodsOrder> goodsOrderList=new ArrayList<GoodsOrder>();
        for (Order_table arg : order_tableList) {
            GoodsOrder goodsOrder=new GoodsOrder();
            Order_item  order_item =  mycommentMapper.findGoodIdByOrderId(arg.getOrder_id());
            Goods goods=goodsMapper.findGoodsByGoods_id(order_item.getGood_id());
            goodsOrder.setGood_id(goods.getGood_id());
            goodsOrder.setGood_name(goods.getGood_name());
            goodsOrder.setPicture_one(goods.getPicture_one());
            goodsOrder.setOrder_id(arg.getOrder_id());
            goodsOrder.setOrder_address(arg.getOrder_address());
            goodsOrder.setOrder_date(arg.getOrder_date());
            goodsOrder.setOrder_state(arg.getOrder_state());
            goodsOrderList.add(goodsOrder);
        }
        return goodsOrderList;
    }

}
